//
//  SSEmoticonAttachment.swift
//  SSEmoticon
//
//  Created by stevenSu on 15/8/6.
//  Copyright © 2015年 stevenSu. All rights reserved.
//

import UIKit

class SSEmoticonAttachment: NSTextAttachment {
    var chs: String?
    
    class func createAttrString(emoticon: SSEmoticon, font: UIFont) -> NSAttributedString {
        let lineheight = font.lineHeight
        let attachment = SSEmoticonAttachment()
        attachment.image = UIImage(named: emoticon.pngPath!)
        attachment.chs = emoticon.chs
        attachment.bounds = CGRect(x: 0, y: -4.5, width: lineheight, height: lineheight)
        
        // 图片属性字符串
        let attrStr = NSMutableAttributedString(attributedString: NSAttributedString(attachment: attachment))
        // 添加字体，add
        attrStr.addAttribute(NSFontAttributeName, value: font, range: NSMakeRange(0, 1))
        return attrStr
    }
    
}
